package com.bdqn.design;

import com.bdqn.design.singleton.Singleton02;

import java.util.concurrent.atomic.AtomicReference;

/**
 * TestSingleton02
 *
 * @author LILIBO
 * @since 2024/7/6
 */
public class TestSingleton02 {

    public static void main(String[] args) {
        AtomicReference<Singleton02> singleton1 = new AtomicReference<>();
        AtomicReference<Singleton02> singleton2 = new AtomicReference<>();
        new Thread(() -> {
            singleton1.set(Singleton02.getInstance());
            System.out.println(singleton1);
        }).start();
        new Thread(() -> {
            singleton2.set(Singleton02.getInstance());
            System.out.println(singleton2);
        }).start();
        try {
            System.out.println("4秒");
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(singleton1.get() == singleton2.get());
    }

}
